package com.njit;

/**
 * Created by ospip on 2017/11/16.
 * Copyright (c) 2017 LLAP. All rights reserved.
 */
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class LoginFrame extends JFrame {

    private JTextField username;
    private JPasswordField password;
    private JButton login, register;

    public LoginFrame() {
        super("Login");
        this.setSize(300, 200);
        this.setLocationRelativeTo(getOwner());
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        this.setLayout(new GridLayout(3, 2));

        // Begin

        this.add(new JLabel("Username"));
        username = new JTextField(10);
        this.add(username);
        this.add(new JLabel("Password"));
        password = new JPasswordField(10);
        this.add(password);

        login = new JButton("Login");
        register = new JButton("Register");
        this.add(login);
        this.add(register);

        login.addActionListener((e) -> {
            String pass = new String(password.getPassword());
            if (username.getText().equals("admin") && pass.equals("123456")) {
                HelloWorld hello = new HelloWorld();
                hello.setVisible(true);
                dispose();
            }
            else {
                JOptionPane.showMessageDialog(null, "Wrong password");
            }
        });
        // End

    }
    public static void main(String[] args) {

        LoginFrame w = new LoginFrame();
        w.setVisible(true);
    }

}